<template>
  <!-- 套餐改价 -->
  <div class="app-container">
    <el-form ref="form" :model="form" label-width="150px">
      <card-find v-model="form.code_zone" @getCardsCb="getCardsCb" />

      <el-form-item label="套餐售价设置">
        <el-row style="display: flex; margin-bottom: 10px" v-for="(item, index) in meals" :key="index">
          <el-col :span="8">{{
            `${item.meal.name} / ${item.meal.meal_period}个月 / ${item.meal.call_mins}分钟 / ${
              item.meal.flow ? item.meal.flow + 'M' : '无限流量'
            } / 售价${item.meal.meal_price}元`
          }}</el-col>
          <el-col :span="4">
            <el-input v-model="meals[index].set_price" :placeholder="`新的售价`" />
          </el-col>
        </el-row>
      </el-form-item>

      <el-form-item>
        <el-button type="primary" @click="submit">修改</el-button>
        <!-- <el-button>取消</el-button> -->
      </el-form-item>
    </el-form>
  </div>
</template>

<script>
import { mealvalue } from '@/api/meal';
import { mapGetters } from 'vuex';
import CardFind from './components/CardFind';

export default {
  components: {
    CardFind,
  },
  data() {
    return {
      form: {},
      meals: {},
    };
  },
  computed: {
    ...mapGetters(['allAgent']),
  },
  methods: {
    getCardsCb(res) {
      this.meals = res.data.meals;
    },
    async submit() {
      await mealvalue({
        form: this.form,
        meals: this.meals,
      });
      this.$message({ message: '操作成功！', type: 'success' });
      setTimeout(() => this.$router.go(-1), 500);
    },
  },
};
</script>

<style lang="scss" scoped>
.app-container {
  padding: 40px 5%;

  .line {
    text-align: center;
  }
}
</style>
